import commands
from pyspades.server import hit_packet

@commands.name('healclass')
def healclass(connection):
    if connection.healer:
        connection.healer = False
        return 'You are no longer a Healer.'
    connection.healer = True
    return 'You are now a Healer.'

commands.add(healclass)

def apply_script(protocol, connection, config):
    
    class HealConnection(connection):
        healer = False
        def on_hit(self, hit_amount, hit_player):
            value = connection.on_hit(self, hit_amount, hit_player)
            if value is not None:
                return value
            if hit_player.team == self.team:
                if self.healer:
                    hit_player.heal_hit(-10)
        def heal_hit(self, value):
            if value<0 and self.hp >= 100: # do nothing at max health
                return
            self.set_hp(self.hp - value)
    return protocol, HealConnection